namespace School.Data.Migrations
{
    using School.Data.Models;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<School.Data.SchoolDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(School.Data.SchoolDbContext context)
        {
            // populate our Students..
            if (!context.Students.Any()) {  
                context.Students.AddOrUpdate(p => p.FirstName,
                    new Student { StudentId = 1, FirstName = "Susan", LastName = "Smith" },
                    new Student { StudentId = 2, FirstName = "Joe", LastName = "Wayne" },
                    new Student { StudentId = 3, FirstName = "Candy", LastName = "Lane" }
                );
            }
            context.SaveChanges();

            // populate our Courses..
            context.Courses.AddOrUpdate(
                p => p.Name,
                    new Course {CourseId = 10, Name="JS 101", Code="211" },
                    new Course {CourseId = 11, Name="c# 101", Code="211" }
                );
            context.SaveChanges();

            // populate our Semesters..
            context.Semesters.AddOrUpdate(
                c => c.SemesterId,
                    new Semester { SemesterId=1, StartDate = DateTime.Parse("2015-1-20"), EndDate=DateTime.Parse("2015-3-20") }
                );
            context.SaveChanges();

            // pupulate our SemesterStudentCourse
            context.SemesterStudentsCourses.AddOrUpdate(
                c => c.CourseId,
                new SemesterStudentCourse { CourseId=10, StudentId=1, SemesterId=1 },
                new SemesterStudentCourse { CourseId=11, StudentId=2, SemesterId=1 },
                new SemesterStudentCourse { CourseId=10, StudentId=3, SemesterId=1 }
                );
            context.SaveChanges();




            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
    }
}
